package com.tju.resource.oauth.controller.tb;

import com.tju.resource.annotation.Log;
import com.tju.resource.model.TbReportOrder;
import com.tju.resource.business.tb_report_order.TbReportOrderService;
import com.tju.resource.result.Result;
import com.tju.resource.tool.enum_utils.FunctionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 报工
 */
@RestController
public class TbReportOrderController {
    private static final String prefix = "report/";
    @Autowired
    private TbReportOrderService tbReportOrderService;

    /**
     * 查询报工
     * @param
     * @return
     */
    @PostMapping(prefix + "list")
    @PreAuthorize("hasAuthority('sys:report:report:list')")
    @Log(type = FunctionType.List)
    public Result<Object> list(@RequestBody Map<String, String> params) {
        return tbReportOrderService.selectTbReportOrder(params);
    }

    /**
     * 添加报工
     * @param tbReportOrder
     * @return
     */
    @PostMapping(prefix + "add")
    @PreAuthorize("hasAnyAuthority('sys:plan:project:report','sys:project:report')")
    @Log(type = FunctionType.Add)
    public Result<Object> insert(@RequestBody TbReportOrder tbReportOrder) {
        return tbReportOrderService.insertTbReportOrder(tbReportOrder);
    }

    /**
     * 修改报工
     * @param tbReportOrder
     * @return
     */
    @PostMapping(prefix + "edit")
    @PreAuthorize("hasAuthority('sys:report:report:edit')")
    @Log(type = FunctionType.Modify)
    public Result<Object> exit(@RequestBody TbReportOrder tbReportOrder) {
        return tbReportOrderService.updateTbReportOrder(tbReportOrder);
    }

    /**
     * 删除报工
     * @param tbReportOrder
     * @return
     */
    @PostMapping(prefix + "delete")
    @PreAuthorize("hasAuthority('sys:report:report:delete')")
    @Log(type = FunctionType.Delete)
    public Result<Object> delete(@RequestBody TbReportOrder tbReportOrder) {
        return tbReportOrderService.deleteTbReportOrder(tbReportOrder);
    }
}
